﻿using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using EventbriteService.Model;

namespace EventbriteService.Linq.Extensibility
{
    public static class EventbriteQueryable
    {
        public static IQueryable<Event> SearchKeywords<Event>(this IQueryable<Event> source, params string[] keywords)
        {
            if (source == null)
                throw new ArgumentException("source");
            if (keywords == null || keywords.Length == 0)
                throw new ArgumentException("keywords");
            return source.Provider.CreateQuery<Event>(Expression.Call(null,
                ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(
                new Type[] { typeof(Event) }),
                new Expression[] { source.Expression, Expression.Constant(keywords) }));

        }

        public static IQueryable<Event> AndSearchKeywords<Event>(this IQueryable<Event> source, params string[] keywords)
        {
            if (source == null)
                throw new ArgumentException("source");
            if (keywords == null || keywords.Length == 0)
                throw new ArgumentException("keywords");
            return source.Provider.CreateQuery<Event>(Expression.Call(null,
                ((MethodInfo)MethodBase.GetCurrentMethod()).MakeGenericMethod(
                new Type[] { typeof(Event) }),
                new Expression[] { source.Expression, Expression.Constant(keywords) }));

        }
    }
}
